<?php

namespace App\VO\Cart\MetaInfo;

use App\BO\Coupon\CouponProductSkuCheck\CheckResultWrapper;
use App\BO\Product\ProductSkuInfoFactory;
use App\BO\PropertyAccessAndSetBO;
use App\Entities\CartItemEntity;
use App\Entities\UserAddressEntity;

class CartFactory
{
    /**
     * @param CartItemEntity $cartItemEntity
     * @return ProductSkuInfo
     * @throws \Exception
     */
    public static function getProductSkuInfo(CartItemEntity $cartItemEntity)
    {
        $productSkuInfo = ProductSkuInfoFactory::getProductSkuInfo($cartItemEntity->getProductSkuId());

        /** * @var ProductSkuInfo $info */
        $info = PropertyAccessAndSetBO::sync($productSkuInfo, new ProductSkuInfo());
        $info->setId($productSkuInfo->getProductSkuId());
        $info->setProductImage($productSkuInfo->getOrderImage());
        return $info;
    }

    /**
     * @param CheckResultWrapper $wrapper
     * @return CouponInfo
     */
    public static function getCouponInfo(CheckResultWrapper $wrapper)
    {
        $couponInfo = new CouponInfo();
        PropertyAccessAndSetBO::sync($wrapper->getCoupon(), $couponInfo);
        $couponInfo->setMessage($wrapper->getMessage());
        return $couponInfo;
    }

    /**
     * @param UserAddressEntity $entity
     * @return UserAddressInfo
     */
    public static function getUserAddressInfo(UserAddressEntity $entity)
    {
        /** * @var UserAddressInfo $userAddressInfo */
        $userAddressInfo = PropertyAccessAndSetBO::sync($entity, new UserAddressInfo());
        $userAddressInfo->setCityId($entity->getProvinceId());
        return $userAddressInfo;
    }
}
